package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.64.140");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");

        Channel channel = connectionFactory.newConnection().createChannel();

        channel.queueDeclare(
                "task_queue",
                true,       //是否持久队列
                false,      //排他队列、独占队列
                false,      //自动删除
                null);    //其他的属性设置

        while (true){
            System.out.println("输入消息:");
            String msg = new Scanner(System.in).nextLine();
            channel.basicPublish(
                    "",     //m3模式再解释
                    "task_queue",
                    MessageProperties.PERSISTENT_TEXT_PLAIN,  //其他消息属性 或者 持久化的纯文本消息
                    msg.getBytes());
        }
    }
}
